//
//  WH_ForgerViewController.m
//  App_6.23
//
//  Created by wanghao on 16/8/3.
//  Copyright © 2016年 wanghao. All rights reserved.
//

#import "WH_ForgerViewController.h"

@interface WH_ForgerViewController ()
@property (weak, nonatomic) IBOutlet UITextField *userNameTF;
@property (weak, nonatomic) IBOutlet UITextField *phoneTF;
@property (weak, nonatomic) IBOutlet UIButton *forgetButton;
@property (weak, nonatomic) IBOutlet UILabel *passWordL;
@property (weak, nonatomic) IBOutlet UIButton *cButton;

@end

@implementation WH_ForgerViewController
- (void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    [self.tabBarController.tabBar setHidden:YES];
}

-(void)viewWillDisappear:(BOOL)animated{
    
    [super viewWillDisappear:animated];
    [self.tabBarController.tabBar setHidden:NO];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = [UIColor colorWithRed:0.98 green:0.98 blue:0.98 alpha:1];
    [_phoneTF addTarget:self action:@selector(textFieldAction:) forControlEvents:UIControlEventEditingChanged];
    
    self.forgetButton.backgroundColor = [UIColor colorWithRed:0.73 green:0.76 blue:0.79 alpha:1];
    [self.forgetButton setUserInteractionEnabled:NO];
    
    self.cButton.backgroundColor = [UIColor colorWithRed:0.73 green:0.76 blue:0.79 alpha:1];
    [self.cButton setUserInteractionEnabled:NO];


}
- (IBAction)copyButton:(UIButton *)sender {
    
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = _passWordL.text;
    
}
- (IBAction)forgetBtn:(UIButton *)sender {
    
    
    [self postData];
}
- (void)textFieldAction:(UITextField *)textField {
    
    if (textField.text.length == 11) {
        self.forgetButton.backgroundColor = [UIColor colorWithRed:0.082 green:0.565 blue:0.847 alpha:1.000];
        [self.forgetButton setUserInteractionEnabled:YES];
    }
    else {
        
        self.forgetButton.backgroundColor = [UIColor colorWithRed:0.73 green:0.76 blue:0.79 alpha:1];
        [self.forgetButton setUserInteractionEnabled:NO];
    }
}

-(void)postData{
    
    NSString *body = [NSString stringWithFormat:@"action=user_forget&user_name=%@&token=%@",_userNameTF.text,self.phoneTF.text];
    
    [WH_AppTools postUrl:URLstr body:body result:HXJSON requestStyle:HXRequestString headerFile:nil success:^(id result) {
        
        NSLog(@"%@",result);
        NSDictionary *dic = result;
        NSString *status = [dic objectForKey:@"status"];
        NSString *message = [dic objectForKey:@"message"];
        NSString *newpwd = [dic objectForKey:@"newpwd"];
        if ([status isEqualToString:@"seccess"]) {

            _passWordL.text = [NSString stringWithFormat:@"%@",newpwd];
            self.cButton.backgroundColor = [UIColor colorWithRed:0.082 green:0.565 blue:0.847 alpha:1.000];
            [self.cButton setUserInteractionEnabled:YES];

            
        }else{
            
            [WSProgressHUD showImage:nil status:message maskType:WSProgressHUDMaskTypeClear];
        }
    } failure:^(NSError *error) {
        
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
